/**
 * zmn产品模块-产品列表
 * @author tanghongjun
 * @since 2018/10/18
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-149',
        done: function () {
            $("div[lay-event='LAYTABLE_EXPORT']").attr('lay-event', 'CUSTOM_EXPORT');
        }
    });
    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    let ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.relateId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        //启用停用
        if (obj.event == "start" || obj.event == "stop") {
            if (ids.length === 0) {
                return layer.alert("请选择至少1条数据！");
            }
            zmnPage.layStartStop(obj, "/product/categorybrand/updateStatus.action", ids.join(","));
        }
        else if(obj.event == "add"){
            zmnLayUtil.openIframeCustom(layer, "/product/categorybrand/addEditView.action?categTwoId="+$("#categId").val(), {title: '品牌关联', shade: 0.8, area:["950px", "750px"]});
        }else if(obj.event=='CUSTOM_EXPORT'){
            let index = layer.load(1, {
                shade: [0.5, '#DBDBDB'] //0.1透明度的白色背景
            });
            zmnUtil.downloadLimitByConfig("/product/categorybrand/outputExcel.action?" + layui.$("#brand_query").serialize(), "品牌关联.xlsx", function () {
                layer.close(index);
            });
        }
        return false;

    });
// 修改排序和首字母
    table.on("edit(zmn-table)", function (obj) {
        if(obj.field=='sort'){
            zmnPage.laySortPositiveInteger(obj.value,"/product/categorybrand/updateSort.action", obj.data.relateId,100000,1000);
        }
    });
    //对外暴露的接口
    exports('plat_categorybrand_list', {});
});

